<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!-- JSTL标签库是一个JSP标签的集合，封装了许多jsp应用程序通用的核心功能-->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!-- JSTL格式化标签 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
		<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css"/>
		<script src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
		<script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
		<style>
			.layui-form{
				margin-top: 30px;
				margin-left: 30px;
			}
		</style>
</head>
<body>
	<form class="layui-form">
		<%-- <c:forEach items="${list}" var="obj"> --%>
		  <input type="hidden" name="id" class="layui-input" value="${obj.id}">
		  <div class="layui-form-item">
   		    <label class="layui-form-label">姓名：</label>
		    <div class="layui-input-inline">
		      <input type="text" name="sName" class="layui-input" value="${obj.sName}">
		    </div>
		  </div>
		  <div class="layui-form-item">
			<label class="layui-form-label">性别：</label>
			<div class="layui-input-inline">
			  <c:if test = ""></c:if>
			  <input type="radio" name="sSex" value="1" <c:if test = "${obj.sSex == 1}">checked=true</c:if> title="男">
			  <input type="radio" name="sSex" value="0" <c:if test = "${obj.sSex == 0}">checked=true</c:if> title="女" >
			</div>
		    <label class="layui-form-label">年级：</label>
		    <div class="layui-input-inline">
		      <input type="text" name="sGrade" class="layui-input" value="${obj.sGrade}">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">学院：</label>
		    <div class="layui-input-inline">
		      <select name="cId" id="cId" lay-filter="f1">
		        <option value="">请选择学院</option>
				  <c:forEach items="${allColleges}" var="college">
				  	<option  <c:if test="${obj.cId == college.id}"> selected=true </c:if> value="${college.id}">
				  	${college.cName}</option>
				  </c:forEach>
		      </select>
		    </div>
			<label class="layui-form-label">专业：</label>
			<div class="layui-input-inline">
			  <select name="mId" id=major>
			   <c:forEach items="${allMajors}" var="major">
			    <c:if test="${obj.cId == major.cId}">
			     <option <c:if test="${obj.mId == major.id}"> selected=true </c:if> value="${major.id}">${major.mName}</option>
			    </c:if>
			   </c:forEach>
			  </select>
			</div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">班级：</label>
		    <div class="layui-input-inline">
		      <input type="text" name="clazz" class="layui-input" value="${obj.clazz}">
		    </div>
			<label class="layui-form-label">就业城市：</label>
			<div class="layui-input-inline">
			  <input type="text" name="empCity" class="layui-input" value="${obj.empCity}">
			</div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">就业单位：</label>
		    <div class="layui-input-inline">
		      <input type="text" name="empCompany" class="layui-input" value="${obj.empCompany}">
		    </div>
			<label class="layui-form-label">岗位：</label>
			<div class="layui-input-inline">
			  <input type="text" name="empStation" class="layui-input" value="${obj.empStation}">
			</div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">薪资：</label>
		    <div class="layui-input-inline">
		      <input type="text" name="salary"  class="layui-input" value="${obj.salary}">
		    </div>
		  </div>
		  <div class="layui-form-item">
		    <label class="layui-form-label">企业类型：</label>
		    <div class="layui-input-block">
		   	  <c:if test = ""></c:if>
		      <input type="radio" name="comType" value="1" <c:if test = "${obj.comType == 1}">checked=true</c:if> title="私企">
		      <input type="radio" name="comType" value="2" <c:if test = "${obj.comType == 2}">checked=true</c:if> title="国企" >
			  <input type="radio" name="comType" value="3" <c:if test = "${obj.comType == 3}">checked=true</c:if> title="外企">
			  <input type="radio" name="comType" value="4" <c:if test = "${obj.comType == 4}">checked=true</c:if> title="集体企业">
			  <input type="radio" name="comType" value="5" <c:if test = "${obj.comType == 5}">checked=true</c:if> title="事业单位">
			  <input type="radio" name="comType" value="6" <c:if test = "${obj.comType == 6}">checked=true</c:if> title="科研院所">
			  <input type="radio" name="comType" value="0" <c:if test = "${obj.comType == 0}">checked=true</c:if> title="待业">
		    </div>
		  </div>
		  
		<%-- </c:forEach> --%>
	</form>
	<div class="layui-form-item">
	  <div class="layui-input-block">
	      <button class="layui-btn" style="width: 500px;" onclick="update()">更新</button>
	  </div>
	 </div>
</body>
<script>
	//更新学生信息
 	function update(){
		//var id = "${str.id}"
		var params = $("form").serialize();
		console.info(params);
		$.ajax({
			url: "s",
			data: params+"&m=updateStudent",
			type: "post",
			success: function(code){
				if(code == '1'){
					alert("更新成功");
				} else {	
					alert("更新失败");
				}
				//延迟关闭
				setTimeout(closeLayer(), 500);
			}
		});
	}
	
    function closeLayer() {
        //关闭弹出层
   /*      var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index); */
        //刷新父页面
        window.parent.location.reload();
    }
    
	layui.use(['layer','form'], function(){
		var layer = layui.layer;
		var form = layui.form;
		
		//二级联动：查询学院对应的专业列表
		//select标签绑定触发事件
		form.on('select(f1)', function(data){
			console.info(data.elem); //得到select原始DOM对象
			console.info(data.value); //得到被选中的值
			var params = "m=listOfCollegeId&cId=" + data.value;
			$.ajax({
				url: "ma",
				data: params,
				type: "POST",
				success: function(obj){
					//将json字符串转为数组
					var arr = JSON.parse(obj);
					//清空子元素
					$("#major").empty();
					//添加子元素
					$.each(arr,function(index, item){
						console.info(item);
						//在元素内部末尾插入子元素
						$("#major").append("<option value='"+item.id+"'>"+item.name+"</option>");
					});
					//重新渲染select下拉框
					form.render('select');
				}	
			});
		});  
	});
</script>
</html>